/*
 * ServerAddrCCU.h
 *
 *  Created on: 2013. 10. 22.
 *      Author: the2
 */

#ifndef SERVERADDRCCU_H_
#define SERVERADDRCCU_H_

#include <string>
#include <vector>
#include <map>
#include <Toolkit/Str.h>


namespace ProjectZ {
namespace NLogic {

class ServerAddrCCU {
public:
	enum {
		__NONE__,
		CH1,
		CH2,
		//test code
		CH3,
		CH4,
		CH5,
		CH6,
		CH7,
		CH8,
		CH9,
		CH10,
		CH11,
		CH12,
		CH13,
		CH14,
		CH15,
		CH16,
		CH17,
		CH18,
		CH19,
		CH20,
		__MAX__,
	};
public:
	struct Data
	{
		int				_serverKey;
		Toolkit::Str<50> _domainName;
		int				_port;
		int				_isActive;
		int				_ccu;
		int				_ch1;
		int				_ch2;
		int				_ch3;
		int				_ch4;
		int				_ch5;
		int				_ch6;
		int				_ch7;
		int				_ch8;
		int				_ch9;
		int				_ch10;
		int				_ch11;
		int				_ch12;
		int				_ch13;
		int				_ch14;
		int				_ch15;
		int				_ch16;
		int				_ch17;
		int				_ch18;
		int				_ch19;
		int				_ch20;
		time_t			_timeStamp;

		Data() : _serverKey(0), _port(0), _isActive(0), _ccu(0),
				_ch1(0), _ch2(0), _ch3(0), _ch4(0), _ch5(0),
				_ch6(0), _ch7(0), _ch8(0), _ch9(0), _ch10(0),
				_ch11(0), _ch12(0), _ch13(0), _ch14(0), _ch15(0),
				_ch16(0), _ch17(0), _ch18(0), _ch19(0), _ch20(0),
				_timeStamp(0) {}

		void Clear()
		{
			_domainName.Clear();
		}

		int GetChannelData(int channel_id);
	};

public:
	ServerAddrCCU();
	virtual ~ServerAddrCCU();

public:
	std::vector<std::pair<int,int>> MapGreaterSort(std::map<int,int> &target);
	typedef std::map<int, Data> SERVERADDRTREE;
	SERVERADDRTREE & GetServerAddrTree() { return _clsServerAddrTree; }
	std::vector<std::pair<int,int>> & GetCCUVec() { return _clsCCUVec; }
	bool SetServerAddr();

public:
	template<template <typename> class P = std::less >
	struct compare_pair_second {
	    template<class T1, class T2> bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
	        return P<T2>()(left.second, right.second);
	    }
	};

private:
	SERVERADDRTREE _clsServerAddrTree;
	std::map<int, int> _clsCCUTree;
	std::vector<std::pair<int,int>> _clsCCUVec;
};


} /* namespace NLogic */
} /* namespace ProjectZ */

#endif /* SERVERADDRCCU_H_ */
